package tests;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;

import sharedrequest.AllocateIDRequest;
import sharedresponse.AllocateIDResponse;

public class OrderSendingTest {
	Socket socket;
	OutputStream os;
	ObjectOutputStream oos;
	InputStream is;
	ObjectInputStream ois;
	Object obj;
	
	@Before
	public void ititBlock() throws Exception{

		InetSocketAddress inetAdress=InetSocketAddress.createUnresolved("127.0.0.1", 2013);
		os=socket.getOutputStream();
		socket.connect(inetAdress);
		oos=new ObjectOutputStream(os);
		is=socket.getInputStream();
		ois=new ObjectInputStream(is);
		
	}
	
	@Test
	public void test() throws IOException,ClassNotFoundException{
		AllocateIDRequest allocateId = new AllocateIDRequest("Gazprom", "Miller");
		oos.writeObject(allocateId);
		obj=ois.readObject();
		System.out.println(obj.toString());
	}
	
	@After
	public void checkResult(){
		assertTrue((obj instanceof AllocateIDResponse));
	}

}
